<include file="Public/base"/>


<!--    <script type="text/javascript" src="__STATIC__/jquery-2.0.3.min.js"></script>
--> <!-- 配置文件 -->
<script type="text/javascript" src="__STATIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__STATIC__/ueditor/ueditor.all.js"></script>
		    
<!--<script type="text/javascript" src="__STATIC__/jquery-1.8.2.min.js"></script>
--><script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
 <style type="text/css">
.txt-area{
display: block;
width: 100%;
height: 80px;
padding: 10px;
box-sizing: border-box;
margin-bottom: 5px;
}
#remaks-txt{
  margin-bottom: 20px;
}
        </style>

<script type="text/javascript">
		//点击x删除图片
		$(document).on('click','.del-img',function(){
			var liObj = $(this).parents('li');
			//找到父级li里面的地址
			var path = liObj.attr('path');
			var thumb = liObj.attr('thumb');
			//alert(thumb);
			//发异步到服务器删除
			$.ajax({
				type:"post",
				url:"<?php $str = $Think.ADMIN_PATH_NAME.$actions['GOODEDITDELPIC']['url'];echo U($str,array('key'=>$actions['GOODEDITDELPIC']['key']))?>",
				data:{path:path,thumb:thumb},
				success:function(data){
					//移除图片
					liObj.remove();
				}
				
			});
		})
		//点击x删除原有图片
		$(document).on('click','.del-img2',function(){
			var liObj = $(this).parents('li');
			//找到父级li里面的地址
			var path = liObj.attr('path');
			var thumb = liObj.attr('thumb');
			//alert($("input[name=id]").val());return false;
			//发异步到服务器删除
			$.ajax({
				type:"post",
				url:"<?php $str = $Think.ADMIN_PATH_NAME.$actions['GOODEDITDELPIC2']['url'];echo U($str,array('key'=>$actions['GOODEDITDELPIC2']['key']))?>",
				data:{path:path,thumb:thumb,gid:$("input[name=id]").val()},
				success:function(data){
					//移除图片
					liObj.remove();
				}
				
			});
		})
		
	
	</script>

<input type="hidden"  name="id" value="{$goodInfo.id}" / >
<div class="pd-20">
    <form action="{$url}" method="post" class="form form-horizontal" id="addGoodForm">
        <div class="row cl">
            <label class="form-label col-3">商品编号</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="gid" value="{$goodInfo.id}" required minlength="2" maxlength="20"
                       id="good_id" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-3">商品名称</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="name" value="{$goodInfo.name}" required minlength="2" maxlength="20"
                       id="good_name" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
        <div class="row cl  uploadBox">
            <label class="form-label col-3">缩略图</label>
            <span class="btn-upload form-group">
                <!--<input class="input-text upload-url" type="text"  style="width:200px" value="上传"  >
                    <a href="javascript:;" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont">&#xe642;</i>
                        上传商品图片</a>-->
                        <!--<img src="{$goodInfo.pic}" alt="" />-->
            <ul>
            	
            <li thumb='{$goodInfo.cover_img}' path='' url=''>
            	<img src='{$goodInfo.cover_img}' style='width:50px;heigth:50px;'/>
            	<a href='javascript:;' style='color:red' class='del-img2'>X</a>
			</li>
            </ul>
            </span>
            <input type="file" value="上传图片"   name="pic" class="input-file" id="file">
            <ul>
            	
            </ul>
             
            
        </div>
        
        <script type="text/javascript">
	                $(function() {
	                	
	                    $('#file').uploadify({
	                    	'formData'    : {'session_id':'<?php echo session_id();?>'},
	                    	
	                        'fileTypeDesc' : '上传文件',//上传描述
	                        'fileTypeExts' : '*.jpg;*.png',
	                        'swf'      : '__STATIC__/uploadify/uploadify.swf',
	                        'uploader' :"<?php $str = $Think.ADMIN_PATH_NAME.$actions['GOODEDITUPLOADIFY']['url'];echo U($str,array('key'=>$actions['GOODEDITUPLOADIFY']['key']))?>",
	                        'buttonText':'选择文件',
	                        'fileSizeLimit' : '2000KB',
	                        'uploadLimit' : 11,//上传文件数
	                        'width':65,
	                        'height':25,
	                        'successTimeout':10,//等待服务器响应时间
	                        'removeTimeout' : 2,//成功显示时间
	                        'onUploadSuccess' : function(file, data, response) {
	                            data=$.parseJSON(data);
	                          //alert(data.show);
	                            var imageUrl = data.name?data.url:'__STATIC__/uploadify/uploadify-cancel.png';
	                            //alert(imageUrl);
	                            //alert(imageUrl);==data.url--http://localhost/yuxiang/uploadify_demo/Upload/Content/15/06/89101435416575.jpg
	                            var li="<li thumb='"+data.thumb+"' path='"+data.savepath+"' url='"+data.url+"'><img src='"+imageUrl+"' style='width:100px;heigth:100px;'/><a href='javascript:;' style='color:red' class='del-img'>X</a>";
	                            //把地址放到隐藏域，这样可以提交到服务器了
	                            /*$.each(data.tu,function(k,v){
	                            	li+="<span><img src='"+v+"' style='width:100px;heigth:100px;'/><a href='javascript:;' style='color:red' class='del-img1'>X</a></span>"
	                            })*/
	                            
	                            li += '<input type="hidden" name="thumb" value="'+data.thumb+'"/>';
	                            li += '<input type="hidden"  name="image" value="'+data.url+'"/>';
	                            li += '<input type="hidden"  name="pic" value="'+data.show+'"/>';
	                            
	                            li += '</li>';
	                            $("div.uploadBox ul").prepend(li);
	                            //alert($("input[name=pic]").val());
	                        }
	                    });
	                });
	                
	            </script>
        
        <div class="row cl">
            <label class="form-label col-3">价格</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="price" value="{$goodInfo.price}" required minlength="2" maxlength="20"
                       id="good_price" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
       <div class="row cl">
            <label class="form-label col-3">状态</label>
             <div class="formControls col-xs-4 col-sm-4">
                <span class="select-box">
          <select class="select sex" size="1" name="is_valid" id="status">
            <option value="0">下架</option>
            <option value="1">上架</option>
                   
          </select>
          <script>
           $(function(){
               var status = {$goodInfo.is_valid};
               $("#status").val(status);
           })
          </script>
        </span>
                    <!-- <input type="text" name="sex" id="" placeholder="" value="{$sale.sex}" class="input-text"> -->
                </div>
        </div>
        <div class="row cl">
            <label class="form-label col-3">批准文号</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="approval_number" value="{$goodInfo.approval_number}" required minlength="2" maxlength="50"
                       id="good_approval" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
         <div class="row cl">
            <label class="form-label col-3">成分</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="ingredients" value="{$goodInfo.ingredients}" required minlength="2" maxlength="120"
                       id="good_ingredients" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
         <div class="row cl">
            <label class="form-label col-3">规格</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="specifications" value="{$goodInfo.specifications}" required minlength="2" maxlength="25"
                       id="good_specifications" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
        
         <div class="row cl">
            <label class="form-label col-3">生产厂家</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="anufacturer" value="{$goodInfo.anufacturer}" required minlength="2" maxlength="20"
                       id="good_anufacturer" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-3">经营企业</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="enterprise" value="{$goodInfo.enterprise}" required minlength="2" maxlength="20"
                       id="good_enterprise" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
        
         <div class="row cl">
            <label class="form-label col-3">主治功能</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="attending" value="{$goodInfo.attending}" required minlength="2" maxlength="125"
                       id="good_attending" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
        <!--<div class="row cl">
            <label class="form-label col-3">用法用量</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="usage" value="{$goodInfo.usage}" required minlength="2" maxlength="125"
                       id="good_usage" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>-->
         <div class="row cl">
           <div class="row cl">
             <label class="form-label col-3">分类</label>
             <div class="formControls col-xs-4 col-sm-4">
                <span class="select-box">
              <select class="select sex" size="1" name="classify" id="classify" value={$classid}>
               <option value="0">请选择</option>
               <volist name="classify" id="data">
               <option value="{$data.id}">{$data.classify}</option>
               </volist>
          </select>
        </span>
                   
                </div>
        </div>
        </div>

        <div class="row cl" id="children">
           
             <label class="form-label col-3">二级分类</label>
             <div class="formControls col-xs-4 col-sm-4">
                <span class="select-box">
              <select class="select sex" size="1" name="classify_new" id="classify_new">
               <option value="0">请选择</option>
               <volist name="children" id="data">
               <option value="{$data.id}">{$data.classify}</option>
               </volist>
          </select>
        </span>
                   
                
        </div>
        </div>
         <div class="row cl">
            <label class="form-label col-3">用法用量</label>
            <div class="formControls col-5">
                
                        <textarea id="remaks-txt" name="usage" class="remaks-txt txt-area" resize="none">{$goodInfo.usage}</textarea>
            </div>
        </div>
        
        
        <div class="row cl">
            <label class="form-label col-3">优势</label>
            <div class="formControls col-5">
                <!--<input type="text" class="input-text" name="drugs_advantage" value="{$goodInfo.advantage}" required minlength="2" maxlength="20"
                       id="drugs_advantage" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">-->
                       <textarea id="adv-txt" name="advantage"  class="dv-txt txt-area" resize="none">{$goodInfo.advantage}</textarea>
            </div>
        </div>
         <div class="row cl">
            <label class="form-label col-3">备注</label>
            <div class="formControls col-5">
                
                        <textarea id="remaks-txt" name="remark" class="remaks-txt txt-area" resize="none">{$goodInfo.remark}</textarea>
            </div>
        </div>
        <!--<div class="row cl">
            <label class="form-label col-3">一级分类</label>
            <div class="formControls col-5">
                <select name="tid" id="select1">
                	<option value=0>请选择</option>
                	<volist name="top" id="vo">
                		<option value="{$vo.id}">{$vo.classify}</option>
                	</volist>
                </select>
            </div>-->
            <script>
            	$(function(){
                    $("#classify").val({$classid['pid']});
                    $("#classify_new").val({$classid['id']});
                    $("#classify").change(function(){
                           var val = $(this).val();
                           val = parseInt(val);
                           if(val!==0)
                            {
                            $.ajax({
                                type:"POST",
                                url:"/Admin/Good/Good/add/type/change/key/GOODADD",
                                data:"id="+val,
                                dataType: "json",
                                success:function(msg)
                                {
                                 
                                  if(msg.status==1)
                                  {
                                      var str = '<label class="form-label col-3">二级分类</label>';
                                      str+='<div class="formControls col-xs-4 col-sm-4">';
                                      str+=' <span class="select-box">';
                                      str+='<select class="select sex" size="1" name="classify_new" id="classify">';
                                      for(var i=0;i<msg.message.length;i++)
                                      {
                                         str+='<option value='+msg.message[i].id+'>'+msg.message[i].classify+'</option>';
                                      }
                                      str+='</select></span></div></div>';

                                     $("#children").children().remove();
                                     $("#children").append(str);
                                  }
                                }
                            })
            }
                    })
            		$("#select1").change(function(){
            			//alert($("input.pic").length);return false;
            			//alert($(this).val());
            			if($(this).val()!=0){
            				
            				
            				$.ajax({
								type:'post',
								data:{id:$(this).val()},
								dataType:'json',
								url:"<?php $str = $Think.ADMIN_PATH_NAME.$actions['GOODEDITADDCLASSIFY']['url'];echo U($str,array('key'=>$actions['GOODEDITADDCLASSIFY']['key']))?>",
								success:function(p){
									//alert(p);
									if(p!='empty'){
										$("#select2").css("display","block");
										var html=''
										$.each(p,function(k,v){
											html+='<option value="'+v.id+'">'+v.classify+'</option>';
										})
										$("#select22").html('');
										$("#select22").append(html);
										//alert($("#select22").val());
										$.ajax({
											type:'post',
											data:{id:$("#select22").val()},
											dataType:'json',
											url:"<?php $str = $Think.ADMIN_PATH_NAME.$actions['GOODEDITADDCLASSIFY']['url'];echo U($str,array('key'=>$actions['GOODEDITADDCLASSIFY']['key']))?>",
											success:function(p){
												//alert(p);
												if(p!='empty'){
													$("#select3").css("display","block");
													var html=''
													$.each(p,function(k,v){
														html+='<option value="'+v.id+'">'+v.classify+'</option>';
													})
													$("#select33").html('');
													$("#select33").append(html);
													//alert($("#select22").val());
												}else{
													$("#select33").val(0);
													$("#select3").css("display","none");
												}
												//window.location.reload();
											}
										});
									}else{
										$("#select22").val(0);
										$("#select2").css("display","none");
									}
									//window.location.reload();
								}
							});
            			}else{
            				$("#select33").val(0);
            				$("#select22").val(0);
            				$("#select2").css("display","none");
            				$("#select3").css("display","none");
            			}
            		})
            		//alert($("#select33").val());
            		$("#select22").change(function(){
            			//alert($(this).val());
            			if($(this).val()!=0){
            				$.ajax({
								type:'post',
								data:{id:$(this).val()},
								dataType:'json',
								url:"<?php $str = $Think.ADMIN_PATH_NAME.$actions['GOODEDITADDCLASSIFY']['url'];echo U($str,array('key'=>$actions['GOODEDITADDCLASSIFY']['key']))?>",
								success:function(p){
									//alert(p);
									if(p!='empty'){
										$("#select3").css("display","block");
										var html=''
										$.each(p,function(k,v){
											html+='<option value="'+v.id+'">'+v.classify+'</option>';
										})
										$("#select33").html('');
										$("#select33").append(html);
										
									}else{
										$("#select33").val(0);
										$("#select3").css("display","none");
									}
									//window.location.reload();
								}
							});
            			}else{
            				$("#select33").val(0);
            				$("#select3").css("display","none");
            			}
            		})
            		
            	})
            </script>
        </div>
       
        
        
         </form>
        <div class="row cl">
            <div class="col-9 col-offset-3">
                <button class="btn btn-primary radius" id="submit" type="submit">确 定
                </button>
                <button class="btn btn-warning radius" onclick="history.back(-1);return false;">返 回</button>
            </div>
        
        
</div>

<script>
	$(function(){
		
		
		$("#submit").click(function(){
		
			$.ajax({
              type:"POST",
              url:"/Admin/Good/Good/add/type/update/key/GOODADD/id/{$goodInfo.id}",
              data:$("#addGoodForm").serialize(),
              success:function(msg)
              {
              	   window.alert("修改成功");
              	   window.location.href="/Admin/Good/Good/index/key/GOODLIST.html";
              }

			})
			
			
		})
	})
</script>

<!--<script src="__JS__/Good/lable.js"></script>-->
